package com.ruoyi.project.system.controller;

import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.CollegePaper;
import com.ruoyi.project.system.service.ICollegePaperService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 学院试卷Controller
 *
 * @author ruoyi
 * @date 2020-11-19
 */
@RestController
@RequestMapping("/system/collegePaper")
public class CollegePaperController extends BaseController
{
    @Autowired
    private ICollegePaperService collegePaperService;

    /**
     * 查询学院试卷列表
     */

    @GetMapping("/list")
    public TableDataInfo list(CollegePaper collegePaper)
    {
        startPage();
        List<CollegePaper> list = collegePaperService.selectCollegePaperList(collegePaper);
        return getDataTable(list);
    }

    /**
     * 导出学院试卷列表
     */

    @Log(title = "学院试卷", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CollegePaper collegePaper)
    {
        List<CollegePaper> list = collegePaperService.selectCollegePaperList(collegePaper);
        ExcelUtil<CollegePaper> util = new ExcelUtil<CollegePaper>(CollegePaper.class);
        return util.exportExcel(list, "paper");
    }

    /**
     * 获取学院试卷详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(collegePaperService.selectCollegePaperById(id));
    }

    /**
     * 新增学院试卷
     */

    @Log(title = "学院试卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollegePaper collegePaper)
    {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return toAjax(collegePaperService.insertCollegePaper(collegePaper,loginUser));
    }

    /**
     * 修改学院试卷
     */

    @Log(title = "学院试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollegePaper collegePaper)
    {
        return toAjax(collegePaperService.updateCollegePaper(collegePaper));
    }

    /**
     * 删除学院试卷
     */

    @Log(title = "学院试卷", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(collegePaperService.deleteCollegePaperByIds(ids));
    }


    /**
     * 获取超管中的试卷信息
     */
    @GetMapping("/getParerQueList")
    public AjaxResult getParerQueList(String id)
    {
        System.out.printf("----"+id);
        return AjaxResult.success(collegePaperService.getParerQueList(Long.parseLong(id)));
    }
}
